﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GeneralDFS.DataEntity.IO;
using GeneralDFS.DataEntity.Nodes;

namespace GeneralDFS.BusinessLogical.FileSystemLogical
{
    public class FileSystemApi:MarshalByRefObject
    {
        private FileSystem fileSystem;

        protected FileSystemApi()
        {

        }

        protected void Init(FileSystem fileSystem)
        {
            if (fileSystem == null) throw new ArgumentNullException("fileSystem");
            this.fileSystem = fileSystem;
        }

        public NodeBase GetNodeByPath(string path)
        {
            return fileSystem.GetNodeByPath(path);
        }

        public Boolean DeleteNodeByPath(String path, string type)
        {
            try
            {
                return fileSystem.DeleteNodeByPath(path, type);
            }
            catch (Exception ex)
            {
                LogUtil.LogError(ex.Message);
                return false;
            }
        }

        public Boolean CreateDirectoryByPath(string path)
        {
            return fileSystem.CreateDirectoryByPath(path);
        }

        public DirectoryNodeInfo GetRootNode()
        {
            return fileSystem.GetRootNode();
        }

        public FileNodeInfo CreateFileByPath(String filePath)
        {
            return fileSystem.CreateFileByPath(filePath);
        }

        public String ReplaceBlocksByPath(String filePath, LocatedBlock[] locatedBlocks)
        {
            return fileSystem.ReplaceBlocks(filePath, locatedBlocks);
        }

        public List<LocatedBlock> GetLocatedBlocks(String filePath)
        {
            return fileSystem.GetLocatedBlocks(filePath);
        }

        public Boolean CreateFileByPath(string directoryPath, FileNodeInfo fileNode)
        {
            return fileSystem.CreateFileByPath(directoryPath, fileNode);
        }

        public Boolean ExistFile(string path)
        {
            return fileSystem.ExistNode(path);
        }

        public Boolean ExistDirectory(string path)
        {
            return fileSystem.ExistNode(path);
        }
    }
}
